package com.itheima.handler;

import com.itheima.common.CustomException;
import com.itheima.common.R;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author longbosheng
 * @Date 2022/6/24 19:15
 * @PackageName:com.itheima.handler
 * @ClassName: GlobalHandler
 * @Description: TODO
 * @Version 1.0
 */
@Log4j2
@RestControllerAdvice
public class GlobalHandler {

    @ExceptionHandler(CustomException.class)
    public R customExceptionHandler(CustomException e){
        log.warn("出现自定义错误！");
        return R.error(e.getMessage());
    }
}
